package com.ddone.finance.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ddone.common.result.Response;
import com.ddone.finance.pojo.entity.UserInfo;
import com.ddone.finance.pojo.vo.UserInfoSearchVo;
import com.ddone.finance.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author ddone
 * @date 2024/4/18-16:10
 */
@RestController
@RequestMapping("/core/admin/user")
@Api(tags = "会员管理")
@Slf4j
// @CrossOrigin
public class AdminUserInfoController {

    @Resource
    private UserInfoService userInfoService;


    @GetMapping("/{page}/{size}")
    @ApiOperation("会员管理列表页")
    public Response<Object> page(@ApiParam(value = "查询对象") UserInfoSearchVo userInfoSearchVo,
                                 @ApiParam(value = "当前页面", required = true, example = "1")
                                 @PathVariable("page") Long page,
                                 @ApiParam(value = "每页记录数", required = true, example = "5")
                                 @PathVariable("size") Long size) {
        Page<UserInfo> pageParam = new Page<>(page, size);
        Page<UserInfo> pageModel = userInfoService.pageWithCondition(pageParam, userInfoSearchVo);
        return Response.ok(pageModel);
    }

    @ApiOperation("锁定和解锁")
    @PutMapping("/lock/{id}/{status}")
    public Response<Object> updateStatus(@ApiParam("用户ID")
                                         @PathVariable("id") Long id,
                                         @ApiParam("锁定状态（0：锁定 1：解锁）")
                                         @PathVariable("status") Integer status) {
        UserInfo userInfo = UserInfo.builder().id(id).status(status).build();
        userInfoService.updateById(userInfo);
        return Response.ok().message(status == 1 ? "解锁成功" : "锁定成功");
    }

}
